$def with (form)

$# :param openlibrary.plugins.upstream.forms.RegisterForm form:

$var title: $_("Sign Up to Open Library")

<div id="contentHead">
    <h1>$_("Sign Up")</h1>
    $if not ctx.user:
        <p class="instruct">$_("Complete the form below to create a new Internet Archive account.")
        <span class="attn remind">$_("Each field is required")</span></p>
</div>

<div id="contentBody">

$def field(input, suffix=''):
    $# :param openlibrary.utils.form.Input input:
    $# :param str suffix: HTML to put at bottom of input

    <div class="formElement">
        <div class="label">
            <label for="$input.id">$input.description</label>
            $if input.help:
                <span class="smaller lighter">$input.help</span>
        </div>
        <div class="input">
            $:input.render()
            <span class="invalid clearfix" id="$(input.id)Message">$input.note</span>
            <span class="sansserif smaller lighter">$:suffix</span>
        </div>
    </div>

$if ctx.user:
    $def user_link(): <a href="$ctx.user.key">$ctx.user.displayname</a>
    <p>$:_("You are already logged into Open Library as %(user)s.", user=str(user_link()))</p>
    <p>$:_('If you\'d like to create a new, different Open Library account, you\'ll need to <a href="javascript:;" onclick="document.forms[\'logout\'].submit()">log out</a> and start the signup process afresh.')</p>
$else:
    <form class="olform create validate" name="signup" method="post" action="">
        $if form.note:
            <div class="note">$form.note</div>

        $def screenname_url(): $_('Your URL'): https://openlibrary.org/people/<span id="userUrl">$(form.username.value or _('screenname'))</span>

        $:field(form.email)
        $:field(form.username, suffix=str(screenname_url()))
        $:field(form.password)
        $:field(form.password2)

        <br/>
        <label>
            $:form.ia_newsletter.render() $:form.ia_newsletter.description
        </label>

        <hr/>

        $if form.has_recaptcha:
            <div class="formElement">
                <div class="label smaller lighter">$_("If you have security settings or privacy blockers installed, please disable them to see the reCAPTCHA.")</div>
                <div class="g-recaptcha" data-sitekey="$form['recaptcha'].public_key"></div>
                <div class="input">
                    $if form['recaptcha'].error:
                        <span class="invalid clearfix">$_('Incorrect. Please try again.')</span>
                </div>
            </div>

        <small>$:_("By signing up, you agree to the Internet Archive's <a href='//archive.org/about/terms.php' target='_blank'>Terms of Service</a>.")</small>

        <div class="formElement bottom">
            <br/>
            <button type="submit" name="signup" id="signup" class="larger">$_("Sign Up")</button>
            <a href="javascript:history.go(-1);" class="smaller attn">$_("Cancel")</a>
        </div>
    </form>

</div>
